<?php 
//最好定时间进行执行该操作
include('./fun.php');include('./hd_fun.php');
$conn=my_sql($cfg);
$pass='';
$p=g('pass');
if($p!=$pass){exit;}
$set=get_set(1);

$sql='select * from '.$cfg['e'].'need_pay where state=0 order by id asc limit 10';
$l=db($sql);

if($l){
foreach($l as $v){
if(!$shop[$v['shop_id']]){
$shop[$v['shop_id']]=get_hd_shop($v['shop_id']);
}    

if($v['trade_no']){$trade_no=$v['trade_no'];}else{
$arr['trade_no']=time().$v['user_id'];
update($cfg['e'].'need_pay',$arr,' where id="'.$v['id'].'"');
$trade_no=$arr['trade_no'];
}
$user=$v;
$re=money_pay_user($v['money'],$trade_no,$v['title'],1);

if(re['err']=='ok'){
$arrs['payment_no']=$re['payment_no'];
$arrs['payment_time']=$re['payment_time'];
$arrs['state']=1;
update($cfg['e'].'need_pay',$arrs,' where id="'.$v['id'].'"');

//账单
$zd['date']=time();
$zd['order_id']=$v['order_id'];
$zd['shop_id']=$v['shop_id'];
$zd['title']=$v['title'];
$zd['user_id']=$v['user_id'];
$zd['c']=$v['c'];
$zd['money']=-$v['money'];
$zd['nickname']=$v['nickname'];
$zd['logo']=$v['logo'];
insert($cfg['e'].'pay',$zd);
zd_balance($shop);//账单结算


//推送公众号消息给商户
if($shop['wx_name']){




}

}
}
}






?>